<?php
namespace app\api\controller;

class Index extends Permission
{
    // 后台首页获取数据
    public function getDatas()
    {
        // 车队总数
        $map = [
            // 'status' => 2,
        ];
        $totalCompany = db('Company')->where($map)->count();
        $map = [
            'status' => 1,
        ];
        $totalDriver = db('Driver')->where($map)->count();

        // 课件下发
        $train = db('DriverTrain')->count();


        // 未学
        $map = [
            'duration_done' => 0
        ];
        $notLearn = db('DriverTrain')->where($map)->count();

        // 在学
        $map = [
            'duration_done' => ['>',0],
            'percent' => ['<',100],
        ];
        $learning = db('DriverTrain')->where($map)->count();
        // 已完成
        $map = [
            'percent' => 100
        ];
        $done = db('DriverTrain')->where($map)->count();

        $data = [
            'totalCompany' => $totalCompany,
            'totalCompany' => 0,
            'totalDriver' => $totalDriver,
            'totalDriver' => 0,
            'notLearn' => $notLearn,
            'notLearn' => 0,
            'done' => $done,
            'done' => 0,
            'learning' => $learning,
            'learning' => 0,
            'sql' => db()->getLastSql()
        ];
        $this->resSuc($data);
    }

    public function getDatasList()
    {
        $list = db('Report')->order('report_date DESC')->limit(10)->select();
        $datas = [];

        $newUser = $totalUser = $play = $playUser = $xAxis = [];
        foreach ($list as $v) {
            $xAxis[] = $v['report_date'];
            $totalTrade[] = $v['trade_total'];
            $totalTradeAmount[] = $v['trade_total_amount'];
        }

        $data = [
            'xAxis' => array_reverse($xAxis),
            'totalTrade' => array_reverse($totalTrade),
            'totalTradeAmount' => array_reverse($totalTradeAmount)
        ];

        $this->resSuc($data);
    }

}
